/**
 * 创元汇 - NAVIGATOR
 * https://menger.me
 * @大梦
 */

import React, {Component} from 'react'
import {
    View,
} from 'react-native'
import { StackNavigator, TabNavigator, TabBarBottom } from 'react-navigation'
import CardStackStyleInterpolator from 'react-navigation/src/views/CardStack/CardStackStyleInterpolator'
import GlobalStyles from '../constants/GlobalStyles'

import stroage from '../store'
import '../store/Global'
import { consoleLog } from '../utils/utilsToast'

import TabBarItem from '../components/common/TabBarItem'
import ShareUtils from '../components/common/shareUtils'
import WebViewPage from '../pages/common/webview'

import Login from '../pages/login'
import Register from '../pages/login/register'
import Repassword from '../pages/login/repassword'
import Caifuguwen from '../pages/login/Caifuguwen'

import Home from '../pages/home'
import Ceshi from '../pages/common/ceshi'

import About from '../pages/about'

import Invest from '../pages/invest'

import Fund from '../pages/fund'
import FundDetail from '../pages/fund/fundDetail'
import JijinHetong from '../pages/fund/jijinHetong'
import JijinGonggao from '../pages/fund/jijinGonggao'
import Renshengou from '../pages/fund/renshengou'
import Jisuanqi from '../pages/fund/jisuanqi'
import Renzheng from '../pages/fund/renzheng'
import RenzhengType from '../pages/fund/renzhengType'
import RenzhengLogin from '../pages/fund/renzhengLogin'
import RenzhengchengnuoLogin from '../pages/fund/RenzhengchengnuoLogin'
import RenzhengTypeLogin from '../pages/fund/renzhengTypeLogin'
import Yinhangka from '../pages/fund/yinhangka'
import AddBank from '../pages/fund/addBank'
import Pinggu from '../pages/fund/pinggu'
import PingguLogin from '../pages/fund/pingguLogin'
import Tijiaochenggong from '../pages/fund/tijiaochenggong'
import Shuishou from '../pages/fund/shuishou'

import Assignment from '../pages/assignment'
import AssignmentDetatil from '../pages/assignment/AssignmentDetatil'
import Contract from '../pages/assignment/Contract'
import TransferDetatil from '../pages/assignment/TransferDetatil'

import User from '../pages/user'
import Shezhi from '../pages/user/shezhi'
import Qiandao from '../pages/user/qiandao'
import Tuijian from '../pages/user/tuijian'
import TuijianZhuce from '../pages/user/tuijianZhuce'
import TuijianBangka from '../pages/user/tuijianBangka'
import TuijianShoutou from '../pages/user/tuijianShoutou'
import Jifen from '../pages/user/jifen'
import Huiyuan from '../pages/user/huiyuan'
import Zichan from '../pages/user/zichan'
import ZichanAdd from '../pages/user/zichanAdd'
import ZichanDetail from '../pages/user/zichanDetail'
import ZichanEdit from '../pages/user/zichanEdit'
import Shangcheng from '../pages/user/shangcheng'
import Shoucang from '../pages/user/shoucang'
import Guanyu from '../pages/user/guanyu'
import Xieyi from '../pages/user/xieyi'
import Gerenxinxi from '../pages/user/gerenxinxi'
import SetMima from '../pages/user/setMima'
import SetMobile from '../pages/user/setMobile'
import Jijin from '../pages/user/jijin'
import Order from '../pages/user/order'
import OrderRenshengouDetail from '../pages/user/orderRenshengouDetail'
import OrderShuhuiDetail from '../pages/user/orderShuhuiDetail'
import OrderZhuanrangDetail from '../pages/user/orderZhuanrangDetail'
import Shuhui from '../pages/user/shuhui'
import Zhuanrang from '../pages/user/zhuanrang'
import ZhuanrangContract from '../pages/user/zhuanrangContract'
import Erweima from '../pages/user/erweima'
import Leijishouyi from '../pages/user/leijishouyi'
import Chengnuoquerenshu from '../pages/user/Chengnuoquerenshu'
import Huifangquerenshu from '../pages/user/Huifangquerenshu'

import NewsWebDetail from '../pages/common/newsWebDetail'
import PdfWebDetail from '../pages/common/pdfWebDetail'

import Xiaoxi from '../pages/xiaoxi'
import Kefu from '../pages/kefu'
import XiaoxiDetail from '../pages/common/xiaoxiDetail'

const TabNavScreen = TabNavigator(
    {
        Home: {
            screen: Home,
            navigationOptions: ({ navigation }) => ({
                header: null,
                tabBarLabel: '首页',
                tabBarIcon: ({focused, tintColor}) => (
                    <TabBarItem
                        subScript = {false}
                        tintColor = {tintColor}
                        focused = {focused}
                        normalImage = {require('../assets/images/tabbar/icon_tabbar_home.png')}
                        selectedImage = {require('../assets/images/tabbar/icon_tabbar_home_cur.png')}
                    />
                ),
            }),
        },
        Fund: {
            screen: Fund,
            navigationOptions: ({ navigation }) => ({
                header: null,
                tabBarLabel: '基金',
                tabBarIcon: ({focused, tintColor}) => (
                    <TabBarItem
                        subScript = {false}
                        tintColor = {tintColor}
                        focused = {focused}
                        normalImage = {require('../assets/images/tabbar/icon_tabbar_fund.png')}
                        selectedImage = {require('../assets/images/tabbar/icon_tabbar_fund_cur.png')}
                    />
                ),
            }),
        },
        // Assignment: {
        //     screen: Assignment,
        //     navigationOptions: ({ navigation }) => ({
        //         header: null,
        //         tabBarLabel: '转让',
        //         tabBarIcon: ({focused, tintColor}) => (
        //             <TabBarItem
        //                 subScript = {false}
        //                 tintColor = {tintColor}
        //                 focused = {focused}
        //                 normalImage = {require('../assets/images/tabbar/icon_tabbar_fund.png')}
        //                 selectedImage = {require('../assets/images/tabbar/icon_tabbar_fund_cur.png')}
        //             />
        //         ),
        //     }),
        // },
        User: {
            screen: User,
            navigationOptions: ({ navigation }) => ({
                header: null,
                tabBarLabel: '我的',
                tabBarIcon: ({focused, tintColor}) => (
                    <TabBarItem
                        subScript = {false}
                        tintColor = {tintColor}
                        focused = {focused}
                        normalImage = {require('../assets/images/tabbar/icon_tabbar_user.png')}
                        selectedImage = {require('../assets/images/tabbar/icon_tabbar_user_cur.png')}
                    />
                ),
            }),
        },
    },
    {
        initialRouteName: 'Home',
        tabBarComponent: TabBarBottom,
        tabBarPosition: 'bottom',
        swipeEnabled: true,
        tabBarOptions: {
            activeTintColor: '#b88950',
            inactiveTintColor: '#a4aab3',
            style: { backgroundColor: '#ffffff' },
            labelStyle: { fontSize: 12, marginBottom: 4,}
        },
    }

);

const App = StackNavigator(
    {
        TabNavScreen: {
            screen: TabNavScreen
        },
        WebViewPage: {
            screen: WebViewPage,
            navigationOptions: ({navigation}) => ({
                header: null,
            }),
        },
        Ceshi: {
            screen: Ceshi,
            navigationOptions: ({navigation}) => ({
                header: null,
                title: '账号登录',
            }),
        },
        Login: {
            screen: Login,
            navigationOptions: ({navigation}) => ({
                header: null,
                title: '账号登录',
            }),
        },
        Register: {
            screen: Register,
            navigationOptions: ({navigation}) => ({
                title: '账号注册',
            }),
        },
        Repassword: {
            screen: Repassword,
            navigationOptions: ({navigation}) => ({
                title: '忘记密码',
            }),
        },
        Caifuguwen: {
            screen: Caifuguwen,
            navigationOptions: ({navigation}) => ({
                title: '忘记密码',
            }),
        },
        Invest: {
            screen: Invest,
            navigationOptions: ({navigation}) => ({
                title: '投资视界',
            }),
        },
        About: {
            screen: About,
            navigationOptions: ({navigation}) => ({
                title: '走进我们',
            }),
        },
        Xiaoxi: {
            screen: Xiaoxi,
            navigationOptions: ({navigation}) => ({
                title: '消息',
            }),
        },
        Kefu: {
            screen: Kefu,
            navigationOptions: ({navigation}) => ({
                title: '客服',
            }),
        },
        ShareUtils: {
            screen: ShareUtils,
            navigationOptions: ({navigation}) => ({
                title: '分享',
            }),
        },
        FundDetail: {
            screen: FundDetail,
            navigationOptions: ({navigation}) => ({
                title: '基金详情',
            }),
        },
        JijinHetong: {
            screen: JijinHetong,
            navigationOptions: ({navigation}) => ({
                title: '基金详情',
            }),
        },
        JijinGonggao: {
            screen: JijinGonggao,
            navigationOptions: ({navigation}) => ({
                title: '基金详情',
            }),
        },
        Renshengou: {
            screen: Renshengou,
            navigationOptions: ({navigation}) => ({
                title: '基金详情',
            }),
        },
        Jisuanqi: {
            screen: Jisuanqi,
            navigationOptions: ({navigation}) => ({
                title: '基金详情',
            }),
        },
        Renzheng: {
            screen: Renzheng,
            navigationOptions: ({navigation}) => ({
                title: '基金详情',
            }),
        },
        RenzhengType: {
            screen: RenzhengType,
            navigationOptions: ({navigation}) => ({
                title: '基金详情',
            }),
        },
        RenzhengLogin: {
            screen: RenzhengLogin,
            navigationOptions: ({navigation}) => ({
                title: '基金详情',
            }),
        },
        RenzhengchengnuoLogin: {
            screen: RenzhengchengnuoLogin,
            navigationOptions: ({navigation}) => ({
                title: '基金详情',
            }),
        },
        RenzhengTypeLogin: {
            screen: RenzhengTypeLogin,
            navigationOptions: ({navigation}) => ({
                title: '基金详情',
            }),
        },
        Yinhangka: {
            screen: Yinhangka,
            navigationOptions: ({navigation}) => ({
                title: '基金详情',
            }),
        },
        AddBank: {
            screen: AddBank,
            navigationOptions: ({navigation}) => ({
                title: '基金详情',
            }),
        },
        Pinggu: {
            screen: Pinggu,
            navigationOptions: ({navigation}) => ({
                title: '基金详情',
            }),
        },
        PingguLogin: {
            screen: PingguLogin,
            navigationOptions: ({navigation}) => ({
                title: '基金详情',
            }),
        },
        Tijiaochenggong: {
            screen: Tijiaochenggong,
            navigationOptions: ({navigation}) => ({
                title: '基金详情',
            }),
        },
        NewsWebDetail: {
            screen: NewsWebDetail,
            navigationOptions: ({navigation}) => ({
                title: '新闻详情',
            }),
        },
        PdfWebDetail: {
            screen: PdfWebDetail,
            navigationOptions: ({navigation}) => ({
                title: '新闻详情',
            }),
        },
        Assignment: {
            screen: Assignment,
            navigationOptions: ({navigation}) => ({
                title: '转让',
            }),
        },
        AssignmentDetatil: {
            screen: AssignmentDetatil,
            navigationOptions: ({navigation}) => ({
                title: '转让详情',
            }),
        },
        Contract: {
            screen: Contract,
            navigationOptions: ({navigation}) => ({
                title: '受让合同',
            }),
        },
        TransferDetatil: {
            screen: TransferDetatil,
            navigationOptions: ({navigation}) => ({
                title: '受让详情',
            }),
        },
        Shezhi: {
            screen: Shezhi,
            navigationOptions: ({navigation}) => ({
                title: '设置',
            }),
        },
        Qiandao: {
            screen: Qiandao,
            navigationOptions: ({navigation}) => ({
                title: '签到',
            }),
        },
        Tuijian: {
            screen: Tuijian,
            navigationOptions: ({navigation}) => ({
                title: '推荐',
            }),
        },
        TuijianZhuce: {
            screen: TuijianZhuce,
            navigationOptions: ({navigation}) => ({
                title: '推荐',
            }),
        },
        TuijianBangka: {
            screen: TuijianBangka,
            navigationOptions: ({navigation}) => ({
                title: '推荐',
            }),
        },
        TuijianShoutou: {
            screen: TuijianShoutou,
            navigationOptions: ({navigation}) => ({
                title: '推荐',
            }),
        },
        Jifen: {
            screen: Jifen,
            navigationOptions: ({navigation}) => ({
                title: '我的积分',
            }),
        },
        Huiyuan: {
            screen: Huiyuan,
            navigationOptions: ({navigation}) => ({
                title: '会员中心',
            }),
        },
        Zichan: {
            screen: Zichan,
            navigationOptions: ({navigation}) => ({
                title: '我的资产',
            }),
        },
        Shangcheng: {
            screen: Shangcheng,
            navigationOptions: ({navigation}) => ({
                title: '积分商城',
            }),
        },
        Shoucang: {
            screen: Shoucang,
            navigationOptions: ({navigation}) => ({
                title: '我的收藏',
            }),
        },
        Guanyu: {
            screen: Guanyu,
            navigationOptions: ({navigation}) => ({
                title: '关于我们',
            }),
        },
        Xieyi: {
            screen: Xieyi,
            navigationOptions: ({navigation}) => ({
                title: '用户协议',
            }),
        },
        User: {
            screen: User,
            navigationOptions: ({navigation}) => ({
                title: '用户协议',
            }),
        },
        Home: {
            screen: Home,
            navigationOptions: ({navigation}) => ({
                title: '用户协议',
            }),
        },
        Fund: {
            screen: Fund,
            navigationOptions: ({navigation}) => ({
                title: '用户协议',
            }),
        },
        SetMobile: {
            screen: SetMobile,
            navigationOptions: ({navigation}) => ({
                title: '用户协议',
            }),
        },
        Jijin: {
            screen: Jijin,
            navigationOptions: ({navigation}) => ({
                title: '用户协议',
            }),
        },
        Order: {
            screen: Order,
            navigationOptions: ({navigation}) => ({
                title: '用户协议',
            }),
        },
        OrderRenshengouDetail: {
            screen: OrderRenshengouDetail,
            navigationOptions: ({navigation}) => ({
                title: '用户协议',
            }),
        },
        OrderShuhuiDetail: {
            screen: OrderShuhuiDetail,
            navigationOptions: ({navigation}) => ({
                title: '用户协议',
            }),
        },
        OrderZhuanrangDetail: {
            screen: OrderZhuanrangDetail,
            navigationOptions: ({navigation}) => ({
                title: '用户协议',
            }),
        },
        Shuhui: {
            screen: Shuhui,
            navigationOptions: ({navigation}) => ({
                title: '用户协议',
            }),
        },
        Zhuanrang: {
            screen: Zhuanrang,
            navigationOptions: ({navigation}) => ({
                title: '用户协议',
            }),
        },
        ZhuanrangContract: {
            screen: ZhuanrangContract,
            navigationOptions: ({navigation}) => ({
                title: '转让合同',
            }),
        },
        Erweima: {
            screen: Erweima,
            navigationOptions: ({navigation}) => ({
                title: '用户协议',
            }),
        },
        Leijishouyi: {
            screen: Leijishouyi,
            navigationOptions: ({navigation}) => ({
                title: '用户协议',
            }),
        },
        Chengnuoquerenshu: {
            screen: Chengnuoquerenshu,
            navigationOptions: ({navigation}) => ({
                title: '用户协议',
            }),
        },
        Huifangquerenshu: {
            screen: Huifangquerenshu,
            navigationOptions: ({navigation}) => ({
                title: '用户协议',
            }),
        },
        SetMima: {
            screen: SetMima,
            navigationOptions: ({navigation}) => ({
                title: '用户协议',
            }),
        },
        Gerenxinxi: {
            screen: Gerenxinxi,
            navigationOptions: ({navigation}) => ({
                title: '用户协议',
            }),
        },
        XiaoxiDetail: {
            screen: XiaoxiDetail,
            navigationOptions: ({navigation}) => ({
                title: '用户协议',
            }),
        },
        ZichanAdd: {
            screen: ZichanAdd,
            navigationOptions: ({navigation}) => ({
                title: '用户协议',
            }),
        },
        ZichanDetail: {
            screen: ZichanDetail,
            navigationOptions: ({navigation}) => ({
                title: '用户协议',
            }),
        },
        ZichanEdit: {
            screen: ZichanEdit,
            navigationOptions: ({navigation}) => ({
                title: '用户协议',
            }),
        },
        Shuishou: {
            screen: Shuishou,
            navigationOptions: ({navigation}) => ({
                title: '用户协议',
            }),
        },
    },
    {
        mode: 'card',
        headerMode: 'screen',
        initialRouteName: 'TabNavScreen',
        navigationOptions: {
            header: null,
            headerBackTitle: null,
            headerTintColor: GlobalStyles.themeColor,
            headerStyle: {
                backgroundColor: '#fff',
            },
            showIcon: true,
            headerTitleStyle: {
                alignSelf: 'center',
            },
            headerRight: (
                <View />
            ),
        },
        transitionConfig:()=>({
            screenInterpolator: CardStackStyleInterpolator.forHorizontal,
        }),
    }
);
const defaultGetStateForAction = App.router.getStateForAction;

App.router.getStateForAction = (action, state) => {

    if ((action.routeName === 'User' && !global.user.loginState) || (action.routeName === 'Kefu' && !global.user.loginState) || (action.routeName === 'Xiaoxi' && !global.user.loginState)) {
        this.routes = [
            ...state.routes,
            {
                key: 'id-' + Date.now(),
                routeName: 'Login',
                params: {
                    name: 'name1'
                }
            },
        ];
        return {
            ...state,
            routes,
            index: this.routes.length - 1,
        };
    }
    return defaultGetStateForAction(action, state);
};

export default App;